package edu.xmut.kakamusic.fragment.chart;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nightonke.boommenu.BoomButtons.TextInsideCircleButton;
import com.nightonke.boommenu.BoomMenuButton;

import edu.xmut.kakamusic.R;
import edu.xmut.kakamusic.bean.entity.BoomMenuItem;
import edu.xmut.kakamusic.viewmodel.ChartViewModel;


public class ChartFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ChartViewModel chartViewModel = new ViewModelProvider(this).get(ChartViewModel.class);
        View root = inflater.inflate(R.layout.fragment_chart, container, false);
        BoomMenuButton bmb = root.findViewById(R.id.bmb);
        chartViewModel.getList().observe(getViewLifecycleOwner(), list -> {
            for (BoomMenuItem boomMenuItem : list) {
                TextInsideCircleButton.Builder builder = new TextInsideCircleButton.Builder();
                builder.normalImageRes(boomMenuItem.getImageId())
                        .normalText(boomMenuItem.getTitle())
                        .listener(index -> {
                            System.out.println(index);
                            switch (index) {
                                case 0:
                                    Navigation.findNavController(root)
                                            .navigate(R.id.action_menu_chart_to_lineFragment);
                                    break;
                                case 1:
                                    Navigation.findNavController(root)
                                            .navigate(R.id.action_menu_chart_to_barFragment);
                                    break;
                                case 2:
                                    Navigation.findNavController(root)
                                            .navigate(R.id.action_menu_chart_to_pieFragment);
                                    break;
                            }
                        });
                bmb.addBuilder(builder);
            }
        });

        return root;
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

    }
}